﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using gbL.NetBoard.Helpers;

namespace gbL.NetBoard.Tests
{
    [TestFixture]
    public class BuilderTests
    {
        public interface ITestMessageContract
        {
            string Name { get; set; }
            int Age { get; set; }
        }

        public class TestMessageContract : ITestMessageContract
        {
            public string Name { get; set; }
            public int Age { get; set; }
        }

        public class TestSenderReceiver : IUseMessages
        {
            public int acceptedMessages = 0;

            public MessagesAdapter Messages
            {
                get; set; 
            }

            public void ConfigureMessages()
            {
                Messages.Accept<ITestMessageContract>(x => { acceptedMessages++; });
                Messages.EnableReceiver();
            }
        }

        [Test]
        public void Built_IUseMessages_should_be_able_to_receive_message_by_contract()
        {
            // A
            Builder builder = new Builder();
            var target = builder.Resolve<TestSenderReceiver>();
            // A
            builder.Blackboard.Add(new TestMessageContract() { Name = "Paul", Age = 31 });
            // A
            Assert.That(target.acceptedMessages, Is.EqualTo(1));
        }

        [Test]
        public void Build_IUseMessages_should_be_able_to_send_message_by_contract()
        {
            // A
            Builder builder = new Builder();
            var target = builder.Resolve<TestSenderReceiver>();
            // A
            target.Messages.Send<ITestMessageContract>(x => { x.Name = "Andrew"; x.Age = 35; });
            // A
            Assert.That(builder.Blackboard.Read(), Has.Count.EqualTo(1));
        }
    }
}
